﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DLM.Domain.Model;
using DLM.Domain.Repositories;
using DLM.Infrastructure.UnitOfWork;
using DLM.Infrastructure.Domain;

namespace DLM.Data.EF.CodeFirst.Repositories
{
    public class AccountRepository : Repository<Account,int>, IAccountRepositroy
    {
        public AccountRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
 
        }

        public new System.Collections.IEnumerator GetEnumerator()
        {
            throw new NotImplementedException();
        }

        public Account FindByName(string accountName)
        {
            if (string.IsNullOrEmpty(accountName))
            {
                throw new ArgumentNullException("Name cannot be null!");
            }
            
            return this.ActiveContext.Account.FirstOrDefault(a => a.AccountName == accountName);
        }


        public Account FindByCode(string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                throw new ArgumentNullException("Code cannot be null!");
            }
            return this.ActiveContext.Account.FirstOrDefault(a => a.ActiveCode == code);
        }


        public Account FindByEmail(string email)
        {
            if (string.IsNullOrEmpty(email))
            {
                throw new ArgumentNullException("Email");
            }

            return this.ActiveContext.Account.FirstOrDefault(a => a.Email == email);
        }
    }
}
